#include "CgManager.h"
#include <stdio.h>
#include <boost/ref.hpp>

CgManager::CgManager(int _argc, char **_argv) {
	argc = _argc;
	argv = _argv;
}

CgManager::~CgManager() {
}




void CgManager::init() {
	//init GLUT
	glutInit(&argc, argv);
	
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
	glutCreateWindow("Shader Manager");
	//glutDisplayFunc();

	// glew
	int err = glewInit();
	if (err != GLEW_OK) {
		printf((char*)glewGetErrorString(err));
		exit(ERROR_GLEW);
	}

    // create FBO (off-screen framebuffer)
    glGenFramebuffersEXT(1, &fb); 
    // bind offscreen framebuffer (that is, skip the window-specific render target)
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	int maxtexsize;
	glGetIntegerv(GL_MAX_TEXTURE_SIZE,&maxtexsize);
	printf("GL_MAX_TEXTURE_SIZE, %d\n",maxtexsize);      
}


void CgManager::operator ()() {
	
	printf("initialize OpenGL\n");
	// viewport for 1:1 pixel=texture mapping
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, w, 0.0, h);
    glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	init();
	printf("...initalized\n");


}
